<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="爱洞ID" prop="platformId">
        <el-input v-model="queryParams.platformId" placeholder="请输入爱洞ID" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="日志类型" prop="logType">
        <el-select v-model="queryParams.logType" placeholder="请选择日志类型" clearable>
          <el-option v-for="dict in dict.type.pay_log_type" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="变更类型" prop="symbol">
        <el-select v-model="queryParams.symbol" placeholder="请选择符" clearable>
          <el-option v-for="dict in dict.type.pay_balance_type" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="余额类型" prop="balanceType">
        <el-select v-model="queryParams.balanceType" placeholder="请选择余额类型" clearable>
          <el-option v-for="dict in dict.type.balance_type" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>


      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>



    <el-table v-loading="loading" :data="payLogList" >
      <el-table-column label="用户头像" align="center" prop="headUrl" >
        <template  slot-scope="scope">
          <ImagePreview :src="scope.row.headUrl" width="50px" height="50px">

          </ImagePreview>
        </template>

      </el-table-column>
       <el-table-column label="用户昵称" align="center" prop="nickName" />
        <el-table-column label="用户手机号" align="center" prop="phone" />
      <el-table-column label="爱动ID" align="center" prop="platformId">
        <template slot-scope="scope">
          <a v-if="scope.row.sex === 1" style="color: #FF6EC7" @click="toUserInfo(scope.row.platformId)">{{ scope.row.platformId }}
          </a>
          <a v-else style="color: #7099F9" @click="toUserInfo(scope.row.platformId)">{{ scope.row.platformId }}
          </a>
        </template>
      </el-table-column>
      <el-table-column label="日志类型" align="center" prop="logType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.pay_log_type" :value="scope.row.logType" />
        </template>
      </el-table-column>
      <el-table-column label="变更类型" align="center" prop="symbol">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.pay_balance_type" :value="scope.row.symbol" />
        </template>
      </el-table-column>
      <el-table-column label="余额类型" align="center" prop="balanceType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.balance_type" :value="scope.row.balanceType" />
        </template>
      </el-table-column>



      <el-table-column label="变更数量" align="center" prop="changeNum" >
        <template slot-scope="scope">
            <span v-if="scope.row.symbol=='+'" style="color: #13ce66;">{{scope.row.symbol+scope.row.changeNum}}</span>
            <span v-if="scope.row.symbol=='-'" style="color: red;">{{scope.row.symbol+scope.row.changeNum}}</span>
        </template>
      </el-table-column>
      <el-table-column label="变更前" align="center" prop="changeNum" >
        <template slot-scope="scope">
          <span v-if="scope.row.balanceType==1">{{JSON.parse(scope.row.walletSnapBefore).goldBalance}}</span>
          <span v-if="scope.row.balanceType==2">{{JSON.parse(scope.row.walletSnapBefore).diamondBalance}}</span>
          <span v-if="scope.row.symbol=='+'" style="color: #13ce66;">{{scope.row.symbol+scope.row.changeNum}}</span>
            <span v-if="scope.row.symbol=='-'" style="color: red;">{{scope.row.symbol+scope.row.changeNum}}</span>
        </template>
      </el-table-column>
      <el-table-column label="变更后" align="center" prop="changeNum" >
        <template slot-scope="scope">
          <span v-if="scope.row.balanceType==1">{{JSON.parse(scope.row.walletSnapAfter).goldBalance}}</span>
          <span v-if="scope.row.balanceType==2">{{JSON.parse(scope.row.walletSnapAfter).diamondBalance}}</span>
        </template>
      </el-table-column>

      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="创建时间" align="center" prop="createTime" />
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />


  </div>
</template>

<script>
  import {
    listPayLog,
  } from "@/api/service/pay/payLog";

  export default {
    name: "PayLog",
    dicts: ['pay_log_type', 'balance_type', 'pay_balance_type'],
    data() {
      return {
        // 按钮loading
        buttonLoading: false,
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 关注-粉丝表格数据
        payLogList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          userId: undefined,
          logType: undefined,
          symbol: undefined,
          balanceType: undefined,
          changeNum: undefined,
          logDate: undefined
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {}
      };
    },
    created() {
      this.getList();
    },
    methods: {
      /** 查询关注-粉丝列表 */
      getList() {
        this.loading = true;
        listPayLog(this.queryParams).then(response => {
          this.payLogList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          id: undefined,
          createTime: undefined,
          createBy: undefined,
          updateTime: undefined,
          updateBy: undefined,
          userId: undefined,
          logType: undefined,
          symbol: undefined,
          balanceType: undefined,
          remark: undefined,
          changeNum: undefined,
          logDate: undefined
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },

      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            this.buttonLoading = true;
            if (this.form.id != null) {
              updatePayLog(this.form).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              }).finally(() => {
                this.buttonLoading = false;
              });
            } else {
              addPayLog(this.form).then(response => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              }).finally(() => {
                this.buttonLoading = false;
              });
            }
          }
        });
      },
      /**
       * 点击用户爱动id跳转到用户页面
       * @param platformId
       */
      toUserInfo(platformId) {
        this.$router.push({path: "/user/appUser", query: {id: platformId}});
      }
    }
  };
</script>
